package com.beamfield.controller.manage.process;

import com.beamfield.common.ApiResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.service.manage.process.ProcessAnalyzeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 工序人员分析
 */
@Controller
@RequestMapping("/cms/process/analyze")
public class ProcessAnalyzeController extends BaseController {

    private final ProcessAnalyzeService processAnalyzeService;

    @Autowired
    public ProcessAnalyzeController(ProcessAnalyzeService processAnalyzeService) {
        this.processAnalyzeService = processAnalyzeService;
    }

    @RequestMapping("/analyze")
    public ModelAndView analyze(){
        return new ModelAndView();
    }
    @RequestMapping("/details")
    public ModelAndView details(){
        return new ModelAndView();
    }

    /**
     * 获取人员工序分析数据
     * @param request
     * @return
     */
    @RequestMapping(value = "readProcessAnalyzeData",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult readProcessAnalyzeData(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        try{
            return processAnalyzeService.getProcessAnalyzeData(beamId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(),HttpResultEnum.EXCEPTION.getMessage());
        }
    }
    /**
     * 获取指定梁的分析数据
     * @param request
     * @return
     */
    @RequestMapping(value = "readProcessAnalyzeDetail",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult readProcessAnalyzeDetail(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        try{
            return processAnalyzeService.readProcessAnalyzeDetail(noticeId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(),HttpResultEnum.EXCEPTION.getMessage());
        }
    }

}
